<?php
	session_start();
/*
  Copyright 2007-2010 by AIDI Content Management System. All rights reserved.

  I. LICENCE TERMS

  1. You may use this script on your website, with or
  without modifications, free of charge.

  2. You may NOT redistribute this script, whether modified
  or not. The script is meant for your personal use on your
  website, and can only be distributed by the author and team 
  described in AIDI CMS.

  3. THE SCRIPT AND ITS DOCUMENTATION ARE PROVIDED
  "AS IS", WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
  IMPLIED WARRANTY OF MECHANTABILITY OR FITNESS FOR A
  PARTICULAR PURPOSE. YOU AGREE TO BEAR ALL RISKS AND
  LIABILITIES ARISING FROM THE USE OF THE SCRIPT,
  ITS DOCUMENTATION AND THE INFORMATION PROVIDED BY THE
  SCRIPTS AND THE DOCUMENTATION.

  If you cannot agree to any of the above conditions, you
  may not use the script. 

  II. SUPPORT

  There is none. You got it without paying a cent, remember?

  If you beg very politely, I may answer :-) - but there's no
  guarantee of that. Officially, there's no support. You're
  better off trying to read the article and following its
  instructions. It's much faster.

  III. CONTACTING THE AUTHOR (BUG REPORTS, LICENSING QUESTIONS)

  Contact Person:
  	- Dimas Fariztha H : dimas_fariztha@yahoo.com (Yahoo Messenger)
  */
//Construct the Functions
//---------------------------------------------------------------------------
	function loginAndRegisterx() {
		global $res;
		if (isset($_SESSION['author'])) {
			if ((isset($res[3])) && ($res[3]=="logout")) {
				unset($_SESSION['sesi_login']);
				unset($_SESSION['author']);
				unset($_SESSION['id_char']);
				unset($_SESSION['admin_type']);
				session_destroy();
				session_start();
			} 		
			header("Location:".DIR_PATH);
			die();
		}
		echo $_POST['val'];
	}
	$smarty->registerPlugin("function",'loginAndRegister','loginAndRegisterx');

	function randomArticlex() {
		global $queryData;
		
		$data = array();
		$dataArray = array();
		$myIDdata = array();
		$numData = 0;
		
		$tipe = 'artikel';
		$limit = 2;
			
		$sql = "SELECT idx FROM tbl_content WHERE tipe='".$tipe."' ORDER BY tanggal DESC";
		$qry = mysql_query($sql);
		while ($row = mysql_fetch_object($qry)) {
			$myIDdata[] = $row->idx;
		}
		
		$NumData = count($myIDdata);
		
		if ($numData!=0) {
			for ($i=0;$i<=$limit;$i++) {
				$iddata = @mt_rand(0,$NumData);
				$cekData = $queryData->selek1("tbl_content","idx='".$myIDdata[$iddata]."' AND tipe='".$tipe."'");
				if ($cekData->idx!="") {
					$data[$i] = $cekData->idx;
				}
			}
			
			$datax = array_unique($data);
			$num = 0;
			foreach ($datax as $val) {
				$cekData = $queryData->selek1("tbl_content","idx='".$val."' AND tipe='".$tipe."' AND status='1'");
				$dataArray[$num][0] = $cekData->idx;
				$dataArray[$num][1] = $cekData->judul;
				$dataArray[$num][2] = $queryData->c_substr($cekData->header_c,100,3);
				$dataArray[$num][3] = $cekData->isi;
				$dataArray[$num][4] = $cekData->author;
				$dataArray[$num][5] = $cekData->tanggal;
				$num++;
			}
		}
				
		return $dataArray;
	}
	$smarty->assign('randomArticle','randomArticlex');

	function eCurrencyStock($params, &$smarty) {
		require "modul/ecurrencystock/view_ecurrencystock.php";	
	}

	function ArrGalery($params, &$smarty) {
		if ($params['limit']!="")
			$limit = $params['limit'];
		else
			$limit = 5;
		
		$data = array();
		$i = 0;
		
		$sql = "SELECT * FROM tbl_upload WHERE RIGHT(`data`,2)='FG' LIMIT ".$limit;
		$qry = mysql_query($sql);
		while ($row = mysql_fetch_object($qry)) {
			$data[$i][0] = explode("[spasi]",$row->data);
			$data[$i][1] = $row->tipe; 	
			$data[$i][2] = $row->tanggal;
			$data[$i][3] = $row->author;
			$data[$i][4] = $row->idx;
			$i++;
		}
		
		return $data;
	}
	$smarty->assign('arrImage','ArrGalery');

	function tagCloudUI($params, &$smarty) {
		global $queryData;
		$expl = "";
		
		if ($params['fieldname']=="")
			$fieldname = 'TAGNAME';
		else
			$fieldname = $params['fieldname'];
			
		if ($params['type']=="")
			$type = 'tag';
		else
			$type = $params['type'];
			
		if ($params['URl']=="")
			$tag = URL_PATH.'index.php/1/s/';
		else
			$tag = $params['URl'];
			
		if ($params['limit']=="")
			$limit = 5;
		else
			$limit = $params['limit'];
		
		$sql = "SELECT * FROM x_fieldvalue WHERE fieldname='".$fieldname."' AND tipe='".$type."'";
		$qry = mysql_query($sql);
		$numrow = mysql_num_rows($qry);
		while ($row = mysql_fetch_object($qry)) {
			$expl .= $row->fieldvalue.',';
		}
		$expl .= substr($expl,0,-1);
				
		$expl = explode(',',$expl);
		$result = array_unique($expl);
		$countResult = count($result);		
		$randData = array_rand($result,$countResult);
		$html = '<div class="tagcloud">';
		if ($countResult<=$limit) {
			foreach ($randData as $num => $val) {
				$fontSize = mt_rand(10,20);
				$val = trim($result[$val]);
				$val = mysql_real_escape_string(trim(strip_tags($val)));
				$val = ereg_replace( ' +', ' ', $val);
				$valx = $val;
				$val = str_replace(' ','+',$val);
				$html .= '<a title="'.$valx.'" style="font-size:'.$fontSize.'px !important" href="'.$tag.'?s='.$val.'">'.$valx.'</a> ';
			}
		} else {
			for ($i=0;$i<=$limit;$i++) {
				$fontSize = mt_rand(10,20);
				$val = trim($result[$randData[$i]]);
				$val = mysql_real_escape_string(trim(strip_tags($val)));
				$val = ereg_replace( ' +', ' ', $val);
				$valx = $val;
				$val = str_replace(' ','+',$val);
				if ($val!='')
					$html .= '<a title="'.$valx.'" style="font-size:'.$fontSize.'px !important" href="'.$tag.'?s='.$val.'">'.$valx.'</a> ';
			}
		}
		
		$html = substr($html,0,-1);
		$html .= '</div>';
		return $html;
	}
	$smarty->registerPlugin("function",'tagUI','tagCloudUI');

	function getDetaileachContent($params, &$smarty) {
		global $queryData;
		$tipe = $params['content'];
		$kode = $params['kode'];
		
		if (is_numeric($kode)) {
			$row = $queryData->selek1("tbl_content","idx='".$kode."'");
			if ($row) {
				switch ($tipe) {
					case 'judul' :
						$html = $row->judul;
					break;
					case 'header_c' :
						$html = $queryData->c_substr(strip_tags(nl2br($row->header_c)),100,15);
					break;
					case 'isi' :
						$html = $row->isi;
					break;
					case 'images' :
						$html = URL_PATH.'images/wi3.png';
					break;
					case 'tanggal' :
						$html = $row->tanggal;
					break;
					case 'author' :
						$html = $row->author;
					break;
					case 'tipe' :
						$html = $row->tipe;
					break;
					case 'status' :
						$html = $row->status;
					break;
				}
			} else {
				$html = '';	
			}
		}
		return $html;
	}
	$smarty->registerPlugin("function",'showEachDetail','getDetaileachContent');

	function bannerX($params, &$smarty) {
		$jum = $params['jum'];
		$lebar = $params['lebar'];
		$panjang = $params['panjang'];
		$batas_tampil = $params['batas_tampil'];
		$pj = $params['pj'];
		$lb = $params['lb'];
		$filenameOnly = $params['filenameOnly'];
		$posisi = $params['posisi'];
		
		$data = banner($jum,$lebar,$panjang,$batas_tampil,$pj,$lb,$filenameOnly,$posisi);	
		return $data;
	}
	$smarty->registerPlugin("function",'banner','bannerX');
	
	function show_datax($params, &$smarty) {
		$page = $params['page']-1;
		switch ($params['data']) {
			case "galeri" :
				require "modul/static/galeri.php";
			break;
			case "download" :
				require "modul/static/view_download.php";
			break;
			case "testimonial" :
				require "modul/static/view_testimonial.php";
			break;
			case "bukutamu" :
				require "modul/static/view_gbook.php";
			break;
			default :
			break;
		}
	}
	$smarty->registerPlugin("function",'show_data','show_datax');
	
	function list_newsx($params, &$smarty) {
		global $DEV_NO_DATA,$queryData;
		$limit = $params['limit'];
		$tipe = str_replace('\'','',$params['tipe']);
		$order = $params['order'];
		$withHeader = $params['withHeader'];
		$jumRandomImage = $params['countRandomImage'];
		
		if ($limit=="")	
			$limit = '0,3';
		if ($tipe=="")
			$tipe = 'berita';
		if ($order=="")
			$order = 'tanggal DESC';
		if ($withHeader!="yes")
			$withHeader = "no";
		if ($jumRandomImage=="")
			$jumRandomImage = 10;
			
		$sql = "SELECT idx,judul,header_c,tanggal FROM tbl_content WHERE tipe='".$tipe."' AND status='1' ORDER BY ".$order." LIMIT ".$limit;
		$qry = mysql_query($sql);
		$num = mysql_num_rows($qry);
		if ($num==0) {
			$data = '<div>'.$DEV_NO_DATA.'<br /><br /></div>';
		} else {
			$data = '<div class="item-list"><ul>';
			while ($row = mysql_fetch_object($qry)) {
				$randData = rand(1,$jumRandomImage);
				$image = 'data/randomImage/image-thumb'.$randData.'.jpg';
				if ($withHeader=="yes") {
					$data .= '<li><h4 class="list-title">'.$queryData->tanggalan($row->tanggal,false,true,false,true).'<a title="'.strip_tags($row->judul).'" class="moreLink" href="'.URL_PATH.'index.php/1/detail/'.$row->idx.'/'.$queryData->permalink($row->idx).'">[more]</a></h4>';
					$data .= '<div class="list-content"><div class="list-thumb"><img class="thumbImage" title="'.strip_tags($row->judul).'" alt="'.strip_tags($row->judul).'" src="'.$image.'" /></div>'.$queryData->c_substr($row->header_c,20,3).'</div>';
					$data .= '</li>';
				} else {
					$data .= '<li><a title="'.strip_tags($row->judul).'" href="'.URL_PATH.'index.php/1/detail/'.$row->idx.'/'.$queryData->permalink($row->idx).'">'.$queryData->c_substr($row->judul,20,3).'</a></li>';
				}
			}
			$data .= '</ul></div>';
		}
		return $data;
	}
	$smarty->registerPlugin("function",'list_news','list_newsx');

	function gbook($params, &$smarty) {
		global $DEV_GBOOK_LOGIN_REQUIRED,$DEV_GBOOK_LABEL,$DEV_GBOOK_MAIL,$DEV_CTRL_SEND,$DEV_GBOOK_SENDER,$DEV_GBOOK_WEBSITE,$DEV_GBOOK_COMMENT,$queryData,$res;
		
		(!is_numeric($params['cols'])) ? $cols = '40' : $cols = $params['cols'];
		(!is_numeric($params['rows'])) ? $rows = '8' : $rows = $params['rows'];
		
		if (isset($_SESSION['sesi_ver'])) {
			$val = '<div class="messages valid">'.$_SESSION['sesi_ver'].'</div>';
			unset($_SESSION['sesi_ver']);
		}
		
		if (isset($_SESSION['author'])) {
			$rowQ = $queryData->selek1("tbl_login","namauser='".$_SESSION['author']."'");
			$alias_name = $rowQ->alias;
		} else {
			$alias_name = $_SERVER['REMOTE_ADDR'];	
		}
		
		$val = '<form class="cmxform" id="guestBook" method="post" action="'.URL_PATH.'modul/gbook/ver_gbook.php?l='.$_SERVER['REQUEST_URI'].'"><fieldset><legend>'.$DEV_GBOOK_LABEL.'</legend>
			<p><label for="mail">'.$DEV_GBOOK_MAIL.'</label><br /><input name="email" size="40" maxlength="50" class="form-text" id="email" /><br /><label for="sender">'.$DEV_GBOOK_SENDER.'</label><br /><input name="pengirim" size="30" maxlength="30" class="form-text" id="pengirim" /><br /><label for="website">'.$DEV_GBOOK_WEBSITE.'</label><br /><input name="website" size="40" maxlength="50" class="form-text" id="website" /><br /><label for="komentar">'.$DEV_GBOOK_COMMENT.'</label><br /><textarea name="isi" id="isi" cols="'.$cols.'" class="form-text" rows="'.$rows.'"></textarea>';
		$val .= '</p>';
		if (defined('USE_RECAPTCHA_PUBLIC_KEY')) {
			$val .= recaptcha(USE_RECAPTCHA_PUBLIC_KEY);
		}
		$val .= '<p><input type="submit" name="submit" id="submit" value="'.$DEV_CTRL_SEND.'">
<input name="act_ver" type="hidden" id="act_ver" value="input" readonly="readonly">
<input name="idbase" type="hidden" id="idbase" value="'.$res[3].'" readonly="readonly">
<input name="ipaddress" type="hidden" id="ipaddress" value="'.$_SERVER['REMOTE_ADDR'].'" readonly="readonly"></p></fieldset>';
		$val .= '</form>';
		return $val;
	}
	$smarty->registerPlugin("function",'guestbook','gbook');

	function testimonial($params, &$smarty) {
		global $DEV_TESTI_LOGIN_REQUIRED,$DEV_TESTI_LABEL,$DEV_TESTI_MAIL,$DEV_CTRL_SEND,$DEV_TESTI_SENDER,$DEV_TESTI_WEBSITE,$DEV_TESTI_COMMENT,$queryData,$res;
		
		(!is_numeric($params['cols'])) ? $cols = '40' : $cols = $params['cols'];
		(!is_numeric($params['rows'])) ? $rows = '8' : $rows = $params['rows'];
		
		if (isset($_SESSION['author'])) {
			if (isset($_SESSION['sesi_ver'])) {
				$val = '<div class="messages valid">'.$_SESSION['sesi_ver'].'</div>';
				unset($_SESSION['sesi_ver']);
			}
			
			if (isset($_SESSION['author'])) {
				$rowQ = $queryData->selek1("tbl_login","namauser='".$_SESSION['author']."'");
				$alias_name = $rowQ->alias;
				(strtolower($_SESSION['author'])=='root') ? $email = AUTHOR_MAIL : $email = $rowQ->namauser;
				if (!validEmail($email)) {
					$email = "";	
				}
			} else {
				$alias_name = $_SERVER['REMOTE_ADDR'];	
			}
			
			$val = '<form class="cmxform" id="testimonial" method="post" action="'.URL_PATH.'modul/testimonial/ver_testimonial.php?l='.$_SERVER['REQUEST_URI'].'"><fieldset><legend>'.$DEV_TESTI_LABEL.'</legend>
				<p><label for="mail">'.$DEV_TESTI_MAIL.'</label><br /><input name="email" size="40" maxlength="50" class="form-text" id="email" value="'.$email.'" readonly="readonly" /><br /><label for="sender">'.$DEV_TESTI_SENDER.'</label><br /><input name="pengirim" size="30" maxlength="30" class="form-text" id="pengirim" value="'.$alias_name.'" readonly="readonly" /><br /><label for="testimonial">'.$DEV_TESTI_COMMENT.'</label><br /><textarea name="isi" id="isi" cols="'.$cols.'" class="form-text" rows="'.$rows.'"></textarea>';
			$val .= '</p>';
			if (defined('USE_RECAPTCHA_PUBLIC_KEY')) {
				$val .= recaptcha(USE_RECAPTCHA_PUBLIC_KEY);
			}
			$val .= '<p><input type="submit" name="submit" id="submit" value="'.$DEV_CTRL_SEND.'">
	<input name="act_ver" type="hidden" id="act_ver" value="input" readonly="readonly">
	<input name="idbase" type="hidden" id="idbase" value="'.$res[3].'" readonly="readonly">
	<input name="ipaddress" type="hidden" id="ipaddress" value="'.$_SERVER['REMOTE_ADDR'].'" readonly="readonly"></p></fieldset>';
			$val .= '</form>';
		} else {
			$val = '<div align="center">'.$DEV_TESTI_LOGIN_REQUIRED.'</div>';
		}
		return $val;
	}
	$smarty->registerPlugin("function",'testimonial','testimonial');

	function pencarian_data($params, &$smarty) {
		if ($params['target']!="")
			$target = $params['target'];
		else
			$target = "_self";	

		if ($params['method']!="")
			$method = $params['method'];
		else
			$method = "get";	

		if ($params['url']!="")
			$url = $params['url'];
		else
			$url = DIR_PATH."index.php/1/s/";	

		if ($params['size']!="")
			$size = $params['size'];
		else
			$size = 20;	
			
		if ($params['text']!="")
			$text = $params['text'];

		$val = '<form action="'.$url.'" method="'.$method.'" enctype="application/x-www-form-urlencoded" target="'.$target.'">
	'.$text.'<input name="s" type="text" size="'.$size.'" /><input name="submit" type="submit" value="Go" />
	</form>';
		return $val;
	}
	$smarty->registerPlugin("function",'formsearch','pencarian_data');
	
	function hasil_cari($params, &$smarty) {
		global $res,$DEV_SEARCH_RESULT,$DEV_NO_DATA,$queryData,$DEV_SENT_BY,$DEV_SENT_ON;

		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		(!empty($params['showview'])) ? $showview = $params['showview'] : $showview = $res[2];
		$numrec = NUMREC;
		$defshow = DEFSHOW;
		$perpage = PAGE;
		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;
		
		if (!empty($params['maxpage']))
			$perpage = $params['maxpage'];

		if ($params['data']!="")
			$cari = htmlspecialchars(strip_tags(trim($params['data'])));
			
		if ($params['limit']!="")
			$limit = 'LIMIT '.strip_tags($params['limit']);
		else
			$limit = "LIMIT ".$piro.",".$perpage;
			
		$cari = ereg_replace( ' +', ' ', $cari);
		$cari = mysql_real_escape_string(trim(strip_tags($cari)));
		$cari = str_replace(' ','+',$cari);
		$cari = explode('+',$cari);
		foreach ($cari as $val) {
			$val = mysql_real_escape_string(strip_tags(trim($val)));
			if ($val!="") {
				$caridata .= " judul REGEXP '".$val."' OR header_c REGEXP '".$val."' OR isi REGEXP '".$val."' OR";	
			}
		}
		
		$caridata = substr($caridata,0,-2);
			
		$sqlQ = "SELECT COUNT(idx) as Jumlah FROM tbl_content WHERE tipe!='bukutamu' AND status='1' AND (".$caridata.")";
		$qryQ = mysql_query($sqlQ);
		$rowQ = mysql_fetch_object($qryQ);
		$numrec = $rowQ->Jumlah;
		$val = '';
		$divpage = $queryData->showpage('index.php',$numrec,$defshow,$perpage,$page,$showview."/".$res[3]);

		$sqlQ = "SELECT * FROM tbl_content WHERE tipe!='bukutamu' AND status='1' AND (".$caridata.") ORDER BY tanggal DESC ".$limit;
		$qryQ = mysql_query($sqlQ);
		
		$arr1 = array('?s=','&submit=Go');
		$arr2 = array('','');
		$arr3 = array($caridata,'^');
		$arr4 = array('<strong>'.$caridata.'</strong>',' ');
		$arrRestrict = array("bukutamu");
		$caridata = strip_tags(str_replace($arr1, $arr2, $res[3]));
		$val .= '<h3>'.$DEV_SEARCH_RESULT.' '.$caridata.'</h3>';		

		if ($numrec!=0) {
			while ($rowQ = mysql_fetch_object($qryQ)) {
				$tipe = explode("-",$rowQ->tipe);
				
				switch ($tipe[0]) {
					case "berita" : $kat = "detail";break;
					case "artikel" : $kat = "detail";break;
					default	: $kat = "dinamis";break;
				}
				
				if (!in_array($tipe[0],$arrRestrict)) {
					$val .= '<div><h2><a title="'.$rowQ->judul.'" href="'.URL_PATH.'index.php/1/'.$kat.'/'.$rowQ->idx.'/'.$queryData->permalink($rowQ->idx).'">'.$rowQ->judul.'</a></h2>';
					$val .= '<div class="author">'.$DEV_SENT_BY.' '.$queryData->cekUser($rowQ->author).' '.$DEV_SENT_ON.' '.$queryData->tanggalan($rowQ->tanggal,false,false,false,true).'</div>';
					$val .= '<div>'.str_replace($arr3,$arr4,$queryData->c_substr(strip_tags($rowQ->header_c),100,15)).'</div></div>';
				}
			}
			$val .= $divpage;
		} else {
			$val .= '<div align="center">'.$DEV_NO_DATA.'</div>';
		}
		
		return $val;
	}
	$smarty->registerPlugin("function",'search_data','hasil_cari');

	function view_newsx($params, &$smarty) {
		global $res,$DEV_NO_DATA,$DEV_SENT_BY,$DEV_SENT_ON,$DEV_MORE,$DEV_CAT,$queryData;

		$kode = strip_tags($res[3]);
					
		$tipe = "tipe='berita'";
		if ($params['tipe']!="")
			$tipe = $params['tipe'];
			
		$withTag = true;
		if ($params['withTag']=='no')
			$withTag = false;

		$withAuthorDate = true;
		if ($params['withAuthorDate']=='no')
			$withAuthorDate = false;
			
		$related = true;
		if ($params['related']=='no')
			$related = false;

		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		(is_numeric($_GET['limitdown'])) ? $limitdown = strip_tags($_GET['limitdown']) : $limitdown = 0;
		($_GET['showview']) ? $showview = strip_tags($_GET['showview']) : $showview = $tipe;
		$numrec = NUMREC;
		$perpage = PAGE;	//jumlah record yang ditampilkan perhalaman
		$defshow = DEFSHOW;
		$sqlfil = array();
		
		if (!empty($params['maxpage']))
			$perpage = $params['maxpage'];

		if ($page!=0)
			$piro = ($page-1)*$perpage;
		else
			$piro = 0;
			
		require "modul/berita/langs/".BASE_LANGUAGE.".inc.php";
		require "modul/berita/view_berita.php";
	}
	$smarty->registerPlugin("function",'view_news','view_newsx');

	function view_eventx($params, &$smarty) {
		global $queryData,$res,$DEV_NO_DATA,$DEV_SENT_BY,$DEV_SENT_ON,$DEV_MORE,$DEV_CAT;
		
		if ($params['tipe']!="")
			$tipe = $params['tipe'];

		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		(is_numeric($_GET['limitdown'])) ? $limitdown = strip_tags($_GET['limitdown']) : $limitdown = 0;
		($_GET['showview']) ? $showview = strip_tags($_GET['showview']) : $showview = $tipe;
		$numrec = NUMREC;
		$perpage = PAGE;	//jumlah record yang ditampilkan perhalaman
		$defshow = DEFSHOW;
		$sqlfil = array();

		$related = true;
		if (!empty($params['maxpage']))
			$perpage = $params['maxpage'];
		
		if ($params['related']==false)
			$related = false;

		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;
		$kode = strip_tags($res[3]);
		
		unset($_SESSION['dataiklan']);
		include "modul/event/langs/".BASE_LANGUAGE.".inc.php";
		include "modul/event/view_event.php";
	}
	$smarty->registerPlugin("function",'list_event','view_eventx');
	
	function show_pagex($params, &$smarty) {
		global $res,$DEV_NO_DATA,$DEV_SENT_BY,$DEV_SENT_ON,$DEV_MORE,$DEV_CAT,$queryData;
		
		if ($params['kode']!="")
			$res[3] = $params['kode'];
			
		if ($params['showauthor']=="no")
			$showauthor = false;
		else
			$showauthor = true;
			
		if ($params['showtitle']=="no")
			$showtitle = false;
		else
			$showtitle = true;			

		$arr1 = array("&gt;");
		$arr2 = array(">");
		$arr3 = array(' ');
		$arr4 = array('%20');
		
		if (is_numeric(trim($res[3]))) {
			$kode = $res[3];
			if ($res[2]=="dinamis") {
				$rowQ = $queryData->selek1("tbl_content","idx='".$res[3]."' AND status='1'");
				$tipe = explode("-",$rowQ->tipe);
				switch ($tipe[0]) {
					case "dinamis" :
						$kategori = explode("[break]",$rowQ->isi);
						if ($rowQ->idx!="") {
							if ($showtitle!=false)
								$html = '<h2>'.strip_tags($rowQ->judul).'</h2>';
							if ($showauthor!=false)
								$html .= '<div class="author">'.$DEV_SENT_BY.' '.$queryData->cekUser($rowQ->author).' '.$DEV_SENT_ON.' '.$queryData->tanggalan($rowQ->tanggal,false,false,false,true).'</div>';
						} else {
							$html = '<div align="center">'.$DEV_NO_DATA.'</div>';
						}
						
						$html .= '<div>'.str_replace($arr1,$arr2,$rowQ->isi)."</div>";
						$html .= '<a class="DiggThisButton DiggMedium"></a>';
						break;
						default :
							if ($rowQ->idx!="") {
								$isi = explode("[break]",$rowQ->isi);
								if ($showtitle!=false)
									$html = '<h2>'.strip_tags($rowQ->judul).'</h2>';
								if ($showauthor!=false)
									$html .= '<div>'.$DEV_SENT_BY.' '.$queryData->cekUser($rowQ->author).' '.$DEV_SENT_ON.' '.$queryData->tanggalan($rowQ->tanggal,false,false,false,true).'</div>';
								$html .= '<div>'.str_replace($arr1,$arr2,$isi[0]).'</div>';
								$html .= '<a class="DiggThisButton DiggMedium"></a>';
							} else {
								$html = '<div align="center">'.$DEV_NO_DATA.'</div>';
							}
						break;
					}
			} else {
				$rowQ = $queryData->selek1("tbl_content","idx='".$res[3]."' AND status='1'");
				$tipe = explode("-",$rowQ->tipe);
				if ($rowQ->idx!="") {
					if ($showtitle!=false)
						$html = '<h2>'.strip_tags($rowQ->judul).'</h2>';
					if ($showauthor!=false)					
						$html .= '<div class="author">'.$DEV_SENT_BY.' '.$queryData->cekUser($rowQ->author).' '.$DEV_SENT_ON.' '.$queryData->tanggalan($rowQ->tanggal,false,false,false,true).'</div>';
					$html .= str_replace($arr1,$arr2,$rowQ->isi);
					$html .= '<a class="DiggThisButton DiggMedium"></a>';
				} else {
					$html = '<div align="center">'.$DEV_NO_DATA.'</div>';
				}
			}
		} else {
			$html = "Data Tidak Ditemukan";
		}
		return $html;
	}
	$smarty->registerPlugin("function",'show_page','show_pagex');
	
	function login_menux($params, &$smarty) {
		global $queryData;
		global $DEV_ADMIN_MENU_ADMIN_SITE,$DEV_ADMIN_MENU_LOGOUT;
		if (!isset($_SESSION['author'])) {
			if ($params['useForm']==true) {
				$html = '<form action="'.URL_PATH.'index.php/1/checkin/" method="post" target="_self">
                        <div class="login">
                        <div id="titleusername">Username</div>
                        <div id="titleinputusername"><input name="emailx" id="emailx" type="text" size="24" maxlength="32" /></div>
                        <div id="titlepassword">Password</div>
                        <div id="titleinputpassword"><input name="passwordx" id="passwordx" type="password" size="24" /></div>
                        <div id="titleinputbutton"><input type="hidden" name="val" id="val" value="login" /><input name="lupapassword" id="lupapassword" type="button" value="LUPA PASSWORD" /><input name="submit" id="submit" type="submit" value="LOGIN" /></div>
                        </div>
                        </form>';
			} else {
				$html = '<div class="item-list"><ul>';
				$html .= '<li><a href="'.URL_PATH.'index.php/1/user/login" title="Login aidiCMS"><img src="'.URL_PATH.'data/aidicmslogin.png" width="100%"></a></li>';
				if (defined('USE_OPENID')) {
					$html .= '<script type="text/javascript">var rpxJsHost = (("https:" == document.location.protocol) ? "https://" : "http://static.");document.write(unescape("%3Cscript src=\'" + rpxJsHost + "rpxnow.com/js/lib/rpx.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script><script type="text/javascript">RPXNOW.overlay = true;RPXNOW.language_preference = \'en\';</script>';
					$html .= '<hr class="lines" />';
					$html .= '<li><a title="Login OpenID" class="rpxnow" onclick="return false;"
		href="https://'.USE_OPENID_ID.'/openid/v2/signin?token_url=http%3A%2F%2F'.$_SERVER['HTTP_HOST'].'%2Fsrc%2Frpx.php"><img src="'.URL_PATH.'data/openid-logo-wordmark.png" width="100%"></a></li>';
				}
				$html .= '</ul></div>';
			}
		} else {
			$html = '<h2>Selamat Datang,<br />'.$queryData->cekUser($_SESSION['id_char'],true).'</h2>';
			$html .= '<div id="loginMenu"><ul>';
			$html .= '<li><a title="'.$DEV_ADMIN_MENU_ADMIN_SITE.'" href="'.URL_PATH.'admin">'.$DEV_ADMIN_MENU_ADMIN_SITE.'</a></li>';
			$html .= '<li><a title="Logout" href="'.URL_PATH.'index.php/1/logout">'.$DEV_ADMIN_MENU_LOGOUT.'</a></li>';
			$html .= '</ul></div>';
		}
		return $html;
	}
	$smarty->registerPlugin("function",'login_menu','login_menux');
	
	function WEB_TITLE_CONTENT($params, &$smarty) {
		global $res,$DEV_CARI_DATA;
				
		if ($res[3]!="") {
			$sqlQ = "SELECT * FROM ikadir_kat WHERE id_dirkat='".mysql_real_escape_string(strip_tags($res[3]))."'";
			$qryQ = mysql_query($sqlQ);
			$numQ = mysql_num_rows($qryQ);
			
			(is_numeric($res[3])) ? (int) $res[3] : "";
			
			$sqlY = "SELECT * FROM tbl_content WHERE idx='".$res[3]."' LIMIT 1";
			$qryY = mysql_query($sqlY);
			$rowY = mysql_fetch_object($qryY);
			
			$title = "";
			
			if (is_numeric($res[3])) $title .= $rowY->judul." | ";
			if (($res[2]!="") && ($res[2]!="s")) 
				$title .= mysql_real_escape_string(strip_tags(strtoupper($res[2])))." | ";
			elseif ($res[2]=='s')
				$title .= mysql_real_escape_string(strip_tags(strtoupper($DEV_CARI_DATA)))." | ";
			
			$title .= WEBSITE_TITLE;
			
		} elseif ($res[2]!="") {
			$title = $res[2]." | ".WEBSITE_TITLE;
		} else {
			$title = WEBSITE_TITLE;
		}
		return $title;
	}
	$smarty->registerPlugin("function",'WEB_TITLE_CONTENT','WEB_TITLE_CONTENT');
	
	function list_iklanx($params, &$smarty) {
		global $res,$queryData;
		if ($params['tipe']!="")
			$tipe = $params['tipe'];

		//jumlah record yang ditampilkan perhalaman
		if ($params['perpage']!="")
			$perpage = $params['perpage'];
		else
			$perpage = PAGE;	

		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		(is_numeric($_GET['limitdown'])) ? $limitdown = strip_tags($_GET['limitdown']) : $limitdown = 0;
		(!empty($params['showview'])) ? $showview = $params['showview'] : $showview = 'iklan';
		$numrec = NUMREC;
		$defshow = DEFSHOW;
		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;
		$kode = strip_tags($res[3]);
		
		$arsip = false;
		$baru = false;
		
		if (is_numeric($params['limit']))
			$limit = 'LIMIT '.$params['limit'];
		
		if (($res[3]=="iklan-arsip") && ($res[2]=="iklan")) {
			$arsip = true;
			$sqlTgl = "AND UNIX_TIMESTAMP(`tanggal`)<'".strtotime(date("Y-m-d"))."'";			
			$kode = "iklan-arsip";
		} elseif (($res[3]=="iklan-terbaru") && ($res[2]=="iklan")) {
			$baru = true;
			$sqlTgl = "AND LEFT(`tanggal`,10)='".date("Y-m-d")."'";
			$kode = "iklan-terbaru";
		} elseif (is_numeric($res[3]) && ($res[2]=="iklan")) {
			$kode = $res[3];
		} else {
			$kode = 0;
		} 
		
		$list = subinsub($tipe,$kode);
		
		$sqlY = "SELECT idx FROM tbl_content WHERE (tipe LIKE '".$tipe."-".$kode."-%' ".$list.") ".$sqlTgl." AND status='1' ORDER BY tanggal DESC ".$limit;
		//echo $sqlY;
		$qryY = mysql_query($sqlY);
		$numrec = mysql_num_rows($qryY);
		$num = 1;
		$x = 0;
	
		while ($rowY = mysql_fetch_object($qryY)) {
			$val[$x] = $rowY->idx;
			$x++;
		}
		@mysql_free_result($qryY);
		//echo_r($val);

		$divpage = $queryData->showpage('index.php',$numrec,$defshow,$perpage,$page,$showview.'/'.$kode."/".$queryData->permalink_kategori($rowQ->id_dirkat));
	
		$arr1 = array();
		$arr2 = array();
	
		for ($i=$piro;$i<($piro+$perpage);$i++) {
			if ($val[$i]!="") {
				$j = ($i+1);
				$rowY = $queryData->selek1("tbl_content","idx='".$val[$i]."' AND status='1' LIMIT 1");
				$kode_kat = explode("-",$rowY->tipe);
				$foto = explode("[break]",$rowY->isi);
				$html .= '<div><h6><div><a title="'.$rowY->judul.'" href="'.URL_PATH.'index.php/1/dinamis/'.$rowY->idx.'/'.$queryData->permalink($rowY->idx).'">'.$j.'. '.$rowY->judul.'</a></div></h6><div>'.$queryData->c_substr(strip_tags($rowY->header_c),100,15).' <a href="'.URL_PATH.'index.php/1/dinamis/'.$rowY->idx.'/'.$queryData->permalink($rowY->idx).'">[more..]</a><br /></div>
				<div>Dikirim Oleh: '.$queryData->cekUser($rowY->author).' | <a title="'.link_kategori($kode_kat[1]).'" href="'.URL_PATH.'index.php/1/iklan/'.$kode_kat[1].'/'.$queryData->permalink_kategori($kode_kat[1]).'">'.link_kategori($kode_kat[1]).'</a><br />';
				
				$html .= $queryData->tanggalan($rowY->tanggal,false,false,false,true);
	
				for ($g=0;$g<3;$g++) {
					if (@is_file('data/ads/'.$foto[$g]))
						$html .= '<a title="Foto: '.$foto[$g].'" href="'.URL_PATH.'data/ads/'.$foto[$g].'" rel="lyteframe" rev="width: 400px; height: 300px; scrolling: auto;">|<b style="background-color: #ffff99;"> foto </b>|</a> ';
				}
	
				$html .= '</div></div>';
			}
		}
		$html .= '<div align="center">'.$divpage.'</div><br /></div>';
				
		return $html;
	}
	$smarty->registerPlugin("function",'list_iklan','list_iklanx');

	function list_subcatx($params, &$smarty) {
		global $res,$queryData;
		if ($params['tipe']!="")
			$tipe = $params['tipe'];
		else
			$tipe = "iklan";
			
		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		(is_numeric($_GET['limitdown'])) ? $limitdown = strip_tags($_GET['limitdown']) : $limitdown = 0;
		($_GET['showview']) ? $showview = strip_tags($_GET['showview']) : $showview = 'iklan';
		$numrec = NUMREC;
		$perpage = PAGE;	//jumlah record yang ditampilkan perhalaman
		$defshow = DEFSHOW;
		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;
		if (is_numeric($res[3])) {
			$kode = strip_tags($res[3]);
			$rowQ = $queryData->selek1("ikadir_kat","id_dirkat='".$kode."' AND tipe='".$tipe."' ORDER BY dir_kat");	
			$val .=  '<div><h1>Daftar iklan '.$rowQ->dir_kat.' di Indonesia</h1>';
			$n = subinsub1($kode);
			$val .= trim($n);		
			$val .= '</div>';
		}
		return $val;	
	}
	$smarty->registerPlugin("function",'list_subcategory','list_subcatx');
	
	function list_top_menu($params, &$smarty) {
		global $res,$queryData;
		
		if ($params['order']!="")
			$order = $params['order'];
		else
			$order = 'id_dirkat';

		if ($params['tipe']!="")
			$tipe = $params['tipe'];
		else
			$tipe = 'topmenu';
		
		if ($params['withhome']!="") {
			if (($res[2]=='detail') || ($res[2]==''))
				$val = '<li class="current selectedLava"><a href="'.URL_PATH.'#!" title="Home">Home</a></li>';
			else
				$val = '<li><a href="'.URL_PATH.'#!" title="Home">Home</a></li>';
		}
		
		$sqlQ = "SELECT id_dirkat,dir_kat,url FROM ikadir_kat WHERE id_dirkatsub='0' AND tipe='".$tipe."' ORDER BY ".$order;
		$qryQ = mysql_query($sqlQ);
		
		while ($rowQ = mysql_fetch_object($qryQ)) {
			$strreplace = strtolower(str_replace(" ","-",$rowQ->dir_kat));
			if ($res[3]==$strreplace)
				$val .= '<li class="current selectedLava"><a title="'.$rowQ->dir_kat.'" href="'.URL_PATH.$rowQ->url.'/'.$queryData->permalink_kategori($rowQ->id_dirkat).'">'.$rowQ->dir_kat.'</a></li>';
			else
				$val .= '<li><a title="'.$rowQ->dir_kat.'" href="'.URL_PATH.$rowQ->url.'/'.$queryData->permalink_kategori($rowQ->id_dirkat).'">'.$rowQ->dir_kat.'</a></li>';
		}
		
		return $val;
	}
	$smarty->registerPlugin("function",'list_topmenu','list_top_menu');

	function list_catx($params, &$smarty) {
		global $queryData;
		if ($params['order']!="")
			$order = $params['order'];
		else
			$order = 'id_dirkat';

		if ($params['tipe']!="")
			$tipe = $params['tipe'];

		if ($params['child']!="")
			$child = false;
		else
			$child = true;		

		if ($params['showcount']!="")
			$showcount = true;
		else
			$showcount = false;		
	
		$sqlQ = "SELECT id_dirkat,dir_kat,url FROM ikadir_kat WHERE id_dirkatsub='0' AND tipe='".$tipe."' ORDER BY ".$order;
		$qryQ = mysql_query($sqlQ);
		$val = '<ul class="cat-content">';
		while ($rowQ = mysql_fetch_object($qryQ)) {
			$sqlB = "SELECT idx FROM tbl_content WHERE tipe LIKE 'dinamis-".$rowQ->id_dirkat."%'";
			$qryB = mysql_query($sqlB);
			$numB = mysql_num_rows($qryB);
			$rowB = mysql_fetch_object($qryB);
			
			$val .= '<li>';
			$val .= '<a title="'.$rowQ->dir_kat.'" href="'.URL_PATH.$rowQ->url.'/'.$queryData->permalink_kategori($rowQ->id_dirkat).'">'.$rowQ->dir_kat.'</a>';
			if ($showcount==true)
				$val .= '('.$numB.')';			
			$val .= '<ul class="sub-category">';			
			if ($child==true) {
				$sqlY = "SELECT id_dirkat,dir_kat,url FROM ikadir_kat WHERE id_dirkatsub='".$rowQ->id_dirkat."' AND tipe='".$tipe."' ORDER BY id_dirkat ASC";
				$qryY = mysql_query($sqlY);
				$num = mysql_num_rows($qryY);
				$i = 1;
				while ($rowY = mysql_fetch_object($qryY)) {
					$sqlC = "SELECT idx FROM tbl_content WHERE tipe LIKE 'dinamis-".$rowY->id_dirkat."%'";
					$qryC = mysql_query($sqlC);
					$numC = mysql_num_rows($qryC);
					$rowC = mysql_fetch_object($qryC);
					if ($num!=$i) {
						$val .= '<li><a title="'.$rowY->dir_kat.'" href="'.URL_PATH.$rowY->url.'/'.$queryData->permalink_kategori($rowY->id_dirkat).'" class="normal">'.$rowY->dir_kat.'</a></li>';
					} else {
						$val .= '<li><a title="'.$rowY->dir_kat.'" href="'.URL_PATH.$rowY->url.'/'.$queryData->permalink_kategori($rowY->id_dirkat).'" class="normal">'.$rowY->dir_kat.'</a></li>';	
					}
					$i++;
				}
				@mysql_free_result($qryY);
			}
			$val .= '</ul></li>';
		}
		$val .= '</ul>';
		@mysql_free_result($qryQ);
		return $val;
	}
	$smarty->registerPlugin("function",'list_category','list_catx');
	
	function list_cat_custom($params, &$smarty) {
		global $queryData;
		if ($params['order']!="")
			$order = $params['order'];
		else
			$order = 'id_dirkat';

		if ($params['tipe']!="")
			$tipe = $params['tipe'];

		if ($params['showcount']!="")
			$showcount = true;
		else
			$showcount = false;		
	
		$sqlQ = "SELECT id_dirkat,dir_kat,url FROM ikadir_kat WHERE id_dirkatsub='0' AND tipe='".$tipe."' ORDER BY ".$order;
		$qryQ = mysql_query($sqlQ);
		$val .= '<ul id="qm0" class="qmmc">';
		while ($rowQ = mysql_fetch_object($qryQ)) {
			$sqlB = "SELECT idx FROM tbl_content WHERE tipe LIKE 'dinamis-".$rowQ->id_dirkat."%'";
			$qryB = mysql_query($sqlB);
			$numB = mysql_num_rows($qryB);
			$rowB = mysql_fetch_object($qryB);
			
			$val .= '<li>';
			$val .= '<a class="qmparent" title="'.$rowQ->dir_kat.'" href="'.URL_PATH.$rowQ->url.'/'.$queryData->permalink_kategori($rowQ->id_dirkat).'">'.$rowQ->dir_kat.'</a>';
			if ($showcount==true)
				$val .= '('.$numB.')';			
			
			$sqlY = "SELECT id_dirkat,dir_kat,url FROM ikadir_kat WHERE id_dirkatsub='".$rowQ->id_dirkat."' AND tipe='".$tipe."' ORDER BY id_dirkat ASC";
			$qryY = mysql_query($sqlY);
			$num = mysql_num_rows($qryY);
			$i = 1;
			if ($num!=0) {
				$val .= '<ul>'; 
			}
			while ($rowY = mysql_fetch_object($qryY)) {
				$sqlC = "SELECT idx FROM tbl_content WHERE tipe LIKE 'dinamis-".$rowY->id_dirkat."%'";
				$qryC = mysql_query($sqlC);
				$numC = mysql_num_rows($qryC);
				$rowC = mysql_fetch_object($qryC);
				if ($num!=$i) {
				$val .= '<li><a title="'.$rowY->dir_kat.'" href="'.URL_PATH.$rowY->url.'/'.$queryData->permalink_kategori($rowY->id_dirkat).'" class="normal">'.$rowY->dir_kat.'</a></li>';
				} else {
				$val .= '<li><a title="'.$rowY->dir_kat.'" href="'.URL_PATH.$rowY->url.'/'.$queryData->permalink_kategori($rowY->id_dirkat).'" class="normal">'.$rowY->dir_kat.'</a></li>';	
				}
				$i++;
			}
			@mysql_free_result($qryY);
			if ($num!=0) {			
				$val .= '</ul>';
			}
			$val .= '</li>';
		}
		$val .= '</ul>';
		@mysql_free_result($qryQ);
		return $val;
	}
	$smarty->registerPlugin("function",'list_category_custom','list_cat_custom');

	function recaptcha($publickey) {
		if (defined('USE_RECAPTCHA')) {
			if (defined('USE_RECAPTCHA_PUBLIC_KEY'))
				$publickey = $publickey;
			require_once 'src/recaptchalib.php';
			$data = recaptcha_get_html($publickey);
		}		
		return $data;
	}
		
	function subkategori($kategori=0,$ssX=0,$editKat=0,$editKode=0,$customQuery="",$viewType=false) {
		$spasi = "";
		for ($c=1;$c<=$ssX;$c++) {
			$spasi .= "&nbsp;&nbsp;&nbsp;";
		}
				
		if ($customQuery!="")
			$tipe = $customQuery;
		$sqlQ = "SELECT * FROM ikadir_kat WHERE id_dirkatsub='".$kategori."' ".$tipe." ORDER BY dir_kat";
		$qryQ = mysql_query($sqlQ);
		while ($rowQ = mysql_fetch_object($qryQ)) {
			if ($rowQ->id_dirkat!=$editKode) {
				$data .= "<option value=".$rowQ->id_dirkat;
				if ($editKat==($rowQ->id_dirkat))
					$data .= " selected ";
				$data .= ">".$spasi."- ".$rowQ->dir_kat;
				if ($viewType==true) {
					$c = true;
					$data .= " [".$rowQ->tipe."]";
				} else {
					$c = false;
				}
				$data .= "</option>\n";
			} else {
				$data .= "<option value=\"SAME\"";
				if ($editKat==($rowQ->id_dirkat))
					$data .= " selected ";
				$data .= " class=\"disable\">".$spasi."- ".$rowQ->dir_kat."</option>\n";
			}
			$data .= subkategori($rowQ->id_dirkat,($ssX+1),$editKat,$editKode,$tipe,$c);			
		}
		@mysql_free_result($qryQ);
		return $data;
	}
	
	function makeThumbnails($oldfile,$newfile,$thumbsize=100) {
		list($width, $height) = getimagesize($oldfile);
		if ($width <= $height) {
			($height <= $thumbsize) ? $modheight = $height : $modheight = $thumbsize;
			$diff = $height / $modheight;
			$modwidth = $width / $diff;
		} else {
			($width <= $thumbsize) ? $modwidth = $width : $modwidth = $thumbsize;
			$diff = $width / $modwidth;
			$modheight = $height / $diff;
		}
		
		if (!is_file($newfile)) {
			$tn = imagecreatetruecolor($modwidth, $modheight) ; 
			$image = imagecreatefromjpeg($oldfile) ; 
			imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
			imagejpeg($tn, $newfile, 100) ; 
		}
	}

	function subinsub1($kode) {
		global $queryData;
		$sql3 = "SELECT * FROM ikadir_kat WHERE id_dirkatsub='".$kode."' ORDER BY dir_kat";
		$qry3 = mysql_query($sql3);
		$n .= "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
		$jum = 1;
		while ($row3 = mysql_fetch_object($qry3)) {
			$n .= "<td valign=\"top\" width=\"33%\" nowrap=\"nowrap\"><h6><div class=\"sub-category\">- <a title=\"".$row3->dir_kat."\" href=\"".URL_PATH."index.php/1/iklan/".$row3->id_dirkat."/".$queryData->permalink_kategori($row3->id_dirkat)."\">";
			if (strlen($row3->dir_kat)>20)
				$n .= $queryData->c_substr($row3->dir_kat,100,15);
			else
				$n .= $row3->dir_kat;
			
			$n .= "</a></div></h6></td>";
			if ($jum>=3) {
				$n .= "</tr><tr>";
				$jum = 0;
			}
			$jum++;
			//$n .= subinsub1(0);
		}
		$n .= "</tr></table>";
		@mysql_free_result($qry3);
		return $n;
	}

	function subinsub($tipenya, $kd) {
		$tipenya = $tipenya;
		$sqlY = "SELECT * FROM ikadir_kat WHERE id_dirkatsub='".$kd."'";
		$qryY = mysql_query($sqlY);
		while ($rowY = mysql_fetch_object($qryY)) {
			$ff .= " OR tipe LIKE '".$tipenya."-".$rowY->id_dirkat."-%' ";
			$ff .= subinsub($tipenya,$rowY->id_dirkat);
		}
		@mysql_free_result($qryY);
		return $ff;
	}

	function extracting($data) {
		$res = explode("/", $data);
		
		for ($i=0;$i < count($res);$i++) {
			if (@eregi("[a-zA-Z0-9]+",$res[$i]))
			$arrData[$i] = $res[$i];
			else
			$arrData[$i] = "";
		}
		
		//geser array ke kiri (karena menghasilkan tanda /)
		array_shift($arrData);
		return $arrData;
	}

	function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
		global $DEV_MONTH;
		$first_of_month = gmmktime(0,0,0,$month,1,$year);
		#remember that mktime will automatically correct if invalid dates are entered
		# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
		# this provides a built in "rounding" feature to generate_calendar()

		$day_names = array(); #generate all the day names according to the current locale
		for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
			$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
	
		list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
		$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
		//Kustom pake bahasa indonesia
		$bulanku = $DEV_MONTH;	
		$month_zero = str_replace("0","",$month);
		$month_name = $bulanku[$month_zero];
		//Sampe sini lalu dipake di baris bawah
		$title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names
	
		//Begin calendar. Uses a real <caption>.
		@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
		if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
		if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
		$calendar = '<table class="calendar">'."\n".
			'<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";
	
		if($day_name_length){
			#if the day names should be shown ($day_name_length > 0)
			#if day_name_length is >3, the full name of the day will be printed
			foreach($day_names as $d)
				$calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
			$calendar .= "</tr>\n<tr>";
		}
		
		if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
		for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
			if($weekday == 7){
				$weekday   = 0; #start a new week
				$calendar .= "</tr>\n<tr>";
			}
			if(isset($days[$day]) and is_array($days[$day])){
				@list($link, $classes, $content) = $days[$day];
				if(is_null($content))  $content  = $day;
				$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
					($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
			}
			else $calendar .= "<td>$day</td>";
		}
		if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days
	
		return $calendar."</tr>\n</table>\n";
	}
		
	function show_content($showview="") { 
		global $DEV_NO_DATA,$DEV_CTRL_SHOW,$DEV_CTRL_ADD,$DEV_CTRL_EDIT,$DEV_CTRL_DELETE,$DEV_CTRL_DETAIL,$DEV_ACTION,$DEV_YES,$DEV_NO,$DEV_ACTION_NOTIFICATION,$DEV_ADMIN_NOW_TIME,$DEV_ADMIN_POSITION,$DEV_CTRL_SUBMIT,$DEV_CTRL_RESET,$DEV_CTRL_SEARCH,$DEV_CTRL_DETAIL,$queryData;
		$sqlQ = "SELECT * FROM modul WHERE `nama_modul`='".$showview."' LIMIT 1";
		$qryQ = mysql_query($sqlQ);
		$rowQ = mysql_fetch_object($qryQ);
		if ((@$rowQ->url!="") && (@trim($showview)!="") && (@is_file($rowQ->url))) {
			$path = dirname($rowQ->url).'/';
			include $path.'langs/'.BASE_LANGUAGE.'.inc.php';
			include $rowQ->url;
		} else include "modul/static/utama.php";
	}
	
	/*PHP 5++ Only */
	function validEmail($val) {
		$emailAddress = $val;
		if(filter_var($emailAddress, FILTER_VALIDATE_EMAIL))
			return true;
		else
			return false;
	}
	
	function sendMail($penerima,$subyek,$katanya,$email_pengirim) {
		global $queryData;
		$row2 = $queryData->selek1("tbl_login","id_user='".$penerima."'");
		$charset='UTF-8';
		$encoded_subject="=?".$charset."?B?".base64_encode($subyek)."?=\n";
		$headers = 'From: ' . $email_pengirim . "\r\n" .'Reply-To: ' . $email_pengirim . "\r\n" .'Content-Type: text/plain; charset='. $charset .';format=flowed\n' .'X-Mailer: PHP/' . phpversion();
		@mail($row2->email,$encoded_subject,$katanya,$headers);
	}
		
	/*
		$footer
	*/
	function footer() {
		$footer = "<blockquote>Copyright &copy; 2010 ".$_SERVER['HTTP_HOST'].". All rights Reserved. All Logos and Trademarks are under AIDI CMS Creative Teams License.</blockquote>";
		return $footer;
	}
?>